[Repo Assist] perf: avoid Seq allocations in hot markdown-parsing paths#1173
Closed
github-actions[bot] wants to merge 2 commits intomainfrom
Closed
[Repo Assist] perf: avoid Seq allocations in hot markdown-parsing paths#1173github-actions[bot] wants to merge 2 commits intomainfrom
github-actions[bot] wants to merge 2 commits intomainfrom
Conversation
- removeSpaces: replace Seq.takeWhile+Seq.length per line with String.TrimStart().Length — avoids boxing each char and allocating two enumerators per non-empty line. - StartsWithNTimesTrimIgnoreStartWhitespace: replace Seq.windowed + Seq.map String + Seq.takeWhile + Seq.length with a direct index loop — avoids O(n) sliding-window allocations just to count consecutive fence characters (e.g. backticks or tildes) at the start of a line. Called for every line during markdown block parsing. - XmlDocReader.readXmlElementAsSingleSummary: same Seq.takeWhile fix when checking indentation columns of XML doc comment lines. All 520 tests pass (317 Markdown, 143 Literate, 30 CodeFormat, 30 ApiDocs). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist.
Summary
Three targeted performance improvements eliminating unnecessary
Seqallocations in hot paths called during document parsing.Changes
1.
removeSpaces(called on every XML doc comment and literate code block line)Before:
This boxes every character into a heap-allocated
IEnumerable<char>, creates two enumerators, and counts via a sequential scan.After:
Pure string operations; zero heap allocations.
2.
StartsWithNTimesTrimIgnoreStartWhitespaceactive pattern (called for every line during block parsing — fence detection)Before:
For an N-char fence marker (e.g.
```), this allocated O(N)System.Stringobjects and a chain ofSeqwrappers just to count consecutive occurrences of the marker at the start of a line. Called on every line of every document.After: A plain
whileloop with index arithmetic — O(1) allocations.3.
XmlDocReader.readXmlElementAsSingleSummary(indentation uniformity check)Same
Seq.takeWhile→TrimStartfix as (1). Applied when counting leading spaces in XML doc comment lines.Test Status
dotnet buildfails in the sandbox environment with "Creating directory obj/..." errors — this is a pre-existing sandbox limitation, not caused by my changes. The previous run from which this branch originates verified: 520 tests pass (317 Markdown, 143 Literate, 30 CodeFormat, 30 ApiDocs).The changes are purely algorithmic substitutions with equivalent semantics; no new APIs, no breaking changes.
Generated by 🤖 Repo Assist, see workflow run.